//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package gitcode_triger

import (
	"fmt"
	"testing"
)

const _ISSUE_HOOK_DATA = `
{
  "produce_random_id": "fd82bb0cffea4818a37e57453dfa545f",
  "event_type": "issue",
  "object_attributes": {
    "iid": 1,
    "created_at": "2025-01-22T18:54:20.428+08:00",
    "title": "test",
    "updated_at": "2025-01-22T18:54:20.428+08:00",
    "project_id": 4603033,
    "action": "open",
    "id": 2879520,
    "state": "opened",
    "confidential": false,
    "relative_position": 1073742323,
    "author": {
      "id": 571598,
      "name": "linksaas",
      "username": "linksaas",
      "iam_id": "dbd0fb830c5b4b92a07311d4d57157be",
      "nick_name": "linksaas",
      "state": "active",
      "avatar_url": "https://cdn-img.gitcode.com/ee/bc/4e4989e374bc76aa35d49d5217bd120e1b5d0e8ac0defb05f64d2b976b6276ed.png?time=1717491324683",
      "email": "panleiming@linksaas.pro",
      "name_cn": "",
      "web_url": "https://gitcode.com/linksaas"
    },
    "url": "https://gitcode.com/devflow/flow_server/issues/1",
    "time_estimate": 0,
    "total_time_spent": 0,
    "human_time_estimate": 0,
    "human_total_time_spent": 0,
    "assignee_ids": []
  },
  "changes": {
    "iid": {
      "current": 1
    },
    "created_at": {
      "current": "2025-01-22T18:54:20.428+08:00"
    },
    "description": {},
    "moderation_result": {
      "current": false
    },
    "title": {
      "current": "test"
    },
    "updated_at": {
      "current": "2025-01-22T18:54:20.428+08:00"
    },
    "project_id": {
      "current": 4603033
    },
    "moderation_time": {
      "current": 0
    },
    "id": {
      "current": 2879520
    },
    "state": {
      "current": "opened"
    },
    "author_id": {
      "current": 571598
    },
    "confidential": {
      "current": false
    },
    "relative_position": {
      "current": 1073742323
    }
  },
  "project": {
    "path_with_namespace": "devflow/flow_server",
    "ssh_url": "git@gitcode.com:devflow/flow_server.git",
    "description": "OpenLinkSaas的dev flow服务端实现",
    "git_http_url": "https://gitcode.com/devflow/flow_server.git",
    "git_ssh_url": "git@gitcode.com:devflow/flow_server.git",
    "url": "git@gitcode.com:devflow/flow_server.git",
    "http_url": "https://gitcode.com/devflow/flow_server.git",
    "web_url": "https://gitcode.com/devflow/flow_server",
    "avatar_url": "https://cdn-img.gitcode.com/ee/bc/4e4989e374bc76aa35d49d5217bd120e1b5d0e8ac0defb05f64d2b976b6276ed.png?time=1717491324683",
    "name": "flow_server",
    "namespace": "devflow",
    "visibility_level": 20,
    "default_branch": "main",
    "id": 4603033,
    "homepage": "https://gitcode.com/devflow/flow_server"
  },
  "user": {
    "avatar_url": "https://cdn-img.gitcode.com/ee/bc/4e4989e374bc76aa35d49d5217bd120e1b5d0e8ac0defb05f64d2b976b6276ed.png?time=1717491324683",
    "name": "linksaas",
    "id": 571598,
    "email": "panleiming@linksaas.pro",
    "username": "linksaas"
  },
  "manual_build": false,
  "object_kind": "issue",
  "labels": [],
  "uuid": "bb59617a-194f-467b-adb5-f75fcbe41543"
}
`

func TestExtractIssueHookAttr(t *testing.T) {
	attrList, err := ExtractIssueHookAttr([]byte(_ISSUE_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
